//
//  SourcesListSearchVC.m
//  NtoccShipper
//
//  Created by zcj on 2021/8/16.
//  Copyright © 2021 zhuchongjin. All rights reserved.
//

#import "SourcesListSearchVC.h"

@interface SourcesListSearchVC ()
@property (nonatomic,strong) CJTextField *tfMainOrderNumber;
@property (nonatomic,strong) CJTextField *tfPlaceOfShipment;
@property (nonatomic,strong) CJTextField *tfPlaceOfReceipt;
@property (nonatomic,strong) CJTextField *tfCoalTypeName;
@property (nonatomic,strong) CJLabel *startTimeLabel;
@property (nonatomic,strong) CJLabel *endTimeLabel;
@end

@implementation SourcesListSearchVC


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setTitleName:@"货源搜索"];
    [self setBackLeftButton:@""];
    [self createTopView];
    [self setDefault];
    
    if (IsNilOrNull(self.dictInfo)) {
        
    }else{
        self.tfMainOrderNumber.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"mainOrderNumber"]];
        self.tfPlaceOfShipment.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"placeOfShipment"]];
        self.tfPlaceOfReceipt.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"placeOfReceipt"]];
        self.tfCoalTypeName.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"coalTypeName"]];
        if ([CJRegular getIsStrEmpty:[CJControl getThreeUnaryValueStr:self.dictInfo[@"startGmtCreated"]]]) {
            self.startTimeLabel.text = @"开始时间";
        }else{
            self.startTimeLabel.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"startGmtCreated"]];
        }
        if ([CJRegular getIsStrEmpty:[CJControl getThreeUnaryValueStr:self.dictInfo[@"endGmtCreated"]]]) {
            self.endTimeLabel.text = @"结束时间";
        }else{
            self.endTimeLabel.text = [CJControl getThreeUnaryValueStr:self.dictInfo[@"endGmtCreated"]];
        }
        
    }
    
}
- (void)setDefault{
    self.tfMainOrderNumber.text = @"";
    self.tfPlaceOfShipment.text = @"";
    self.tfPlaceOfReceipt.text = @"";
    self.tfCoalTypeName.text = @"";
    self.startTimeLabel.text = @"开始时间";
    self.endTimeLabel.text = @"结束时间";
}
- (void)createTopView{

    CGRect rcFrame = CGRectMake(0, kTopHeight, [[UIScreen mainScreen] bounds].size.width, 0);
    FlexFrameView *header = [[FlexFrameView alloc] initWithFlex:@"SourcesListSearchView" Frame:rcFrame Owner:self];
    header.flexibleHeight = YES;
    [header layoutIfNeeded];
    [self.view addSubview:header];
}

- (void)btnSaveInvoiceInfo{

    
    int bageNums = 0;
    
    if (![CJControl getIsEmpty:self.tfMainOrderNumber.text]) {
        bageNums++;
    }
    if (![CJControl getIsEmpty:self.tfPlaceOfShipment.text]) {
        bageNums++;
    }
    if (![CJControl getIsEmpty:self.tfPlaceOfReceipt.text]) {
        bageNums++;
    }
    if (![CJControl getIsEmpty:self.tfCoalTypeName.text]) {
        bageNums++;
    }
    if (![CJControl getIsEmpty:self.startTimeLabel.text] && ![self.startTimeLabel.text isEqualToString:@"开始时间"]) {
        bageNums++;
    }
    if (![CJControl getIsEmpty:self.endTimeLabel.text] && ![self.endTimeLabel.text isEqualToString:@"结束时间"]) {
        bageNums++;
    }
    
    NSDictionary *dicPra = @{
        @"mainOrderNumber":self.tfMainOrderNumber.text,
        @"placeOfShipment":self.tfPlaceOfShipment.text,
        @"placeOfReceipt":self.tfPlaceOfReceipt.text,
        @"coalTypeName":self.tfCoalTypeName.text,
        @"startGmtCreated":[self.startTimeLabel.text isEqualToString:@"开始时间"] ? @"" : self.startTimeLabel.text,
        @"endGmtCreated":[self.endTimeLabel.text isEqualToString:@"结束时间"] ? @"" : self.endTimeLabel.text,
        @"bageNums":@(bageNums)
    };
    

    if (self.blockSerach) {
        self.blockSerach(dicPra);
        [self pop];
    }
}

- (void)btnSetDefaultAction{
    [self setDefault];
}
- (void)startTimeAction{
    WS(ws);
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title =  @"装车时间";
    datePickerView.minDate = [NSDate br_setYear:2016 month:5 day:1];
    datePickerView.maxDate = [NSDate br_setYear:2035 month:5 day:1];
    datePickerView.resultBlock = ^(NSString *selectValue) {
    ws.startTimeLabel.text = CJStringWithFormat(@"%@",selectValue);
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor cjMainColor]];
    datePickerView.pickerStyle = customStyle;
    [datePickerView show];
}
- (void)endTimeAction{
    WS(ws);
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"卸车时间";
    datePickerView.minDate = [NSDate br_setYear:2016 month:5 day:1];
    datePickerView.maxDate = [NSDate br_setYear:2035 month:5 day:1];
    datePickerView.resultBlock = ^(NSString *selectValue) {
    ws.endTimeLabel.text = CJStringWithFormat(@"%@",selectValue);
    };
    
    BRPickerStyle *customStyle = [BRPickerStyle pickerStyleWithThemeColor:[UIColor cjMainColor]];
    datePickerView.pickerStyle = customStyle;
    [datePickerView show];
}

@end

